home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TeX 1995 July
/
TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO
/
web
/
noweb
/
src
/
icon
/
totex.icn
< prev
next >
Wrap
Text File
|
1995-02-24
|
13KB
|
339 lines
#line 4 "totex.nw"
# Copyright 1991 by Norman Ramsey. All rights reserved.
# See file COPYRIGHT for more information.
#line 10 "totex.nw"
procedure main(args)
local delay
#line 38 "totex.nw"
text := 1
#line 116 "totex.nw"
defns := table("")
#line 250 "totex.nw"
TeXspecials := '\\{}$^_ ~%'
#line 13 "totex.nw"
delay := !args == "-delay"
noindex := !args == "-noindex"
while inputline := read() do inputline ? {
#line 69 "totex.nw"
if ="@text " then { text +:= *(line := tab(0))
writes(if \quoting then TeXliteral(line)
else if \code then escape(line, '{}\\')
else line) } else
#line 74 "totex.nw"
if ="@nl" & pos(0) then { if /code then {
#line 89 "totex.nw"
if text = 0 then writes("\\nwdocspar")
text := 1
#line 74 "totex.nw"
}
if \quoting then writes("\\nwnewline")
write() } else
#line 60 "totex.nw"
if ="@begin code " then { code := 1 ; writes("\\nwbegincode{", tab(0), "}") } else
if ="@end code " then { code := &null ; writes("\\nwendcode{}")
lastdefnlabel := &null } else
#line 96 "totex.nw"
if ="@defn " then { writes("\\sublabel{", \lastxreflabel, "}")
writes("\\nwmargintag{", label2tag(\lastxreflabel), "}")
writes("\\moddef{", convquotes(name := tab(0)),
("~" || label2tag(\lastxrefref)) | "",
"}\\", defns[name], "endmoddef")
lastdefnlabel := lastxreflabel
#line 154 "totex.nw"
every lastxreflabel | lastxrefref := &null
#line 103 "totex.nw"
defns[name] := "plus" } else
#line 64 "totex.nw"
if ="@begin docs " then { if \delay & match(0) then
#line 84 "totex.nw"
&null
#line 64 "totex.nw"
else {text := 0; writes("\\nwbegindocs{",tab(0),"}")} } else
if ="@end docs " then { if \delay & match(0) then
#line 86 "totex.nw"
{ writes("\\nwfilename{", filename, "}"); delay := &null }
#line 66 "totex.nw"
else writes("\\nwenddocs{}") } else
#line 105 "totex.nw"
if ="@use " then { writes("\\LA{}", convquotes(name := tab(0)),
("~" || label2tag(\lastxrefref)) | "",
"\\RA{}") } else
#line 140 "totex.nw"
if ="@xref " then {
#line 142 "totex.nw"
if ="label " then { lastxreflabel := tab(0) } else
if ="ref " then { lastxrefref := tab(0) } else
if ="begindefs" & pos(0) then { writes("\\nwalsodefined{") } else
if ="defitem " then { writes("\\\\{", tab(0), "}") } else
if ="enddefs" & pos(0) then { writes("}") } else
if ="beginuses" & pos(0) then { writes("\\nwused{") } else
if ="useitem " then { writes("\\\\{", tab(0), "}") } else
if ="enduses" & pos(0) then { writes("}") } else
if ="notused " then { writes("\\nwnotused{", TeXliteral(tab(0)), "}") } else
if ="nextdef " then { } else
if ="prevdef " then { } else
#line 219 "totex.nw"
if ="beginchunks" & pos(0) then { } else
if ="chunkbegin " then { label := tab(upto(' ')); =" "
writes("\\nwixlogsorted{c}{{", convquotes(tab(0)),
"}{", label, "}{") } else
if ="chunkuse " then { writes("\\nwixu{", tab(0), "}") } else
if ="chunkdefn " then { writes("\\nwixd{", tab(0), "}") } else
if ="chunkend" & pos(0) then { write("}}%") } else
if ="endchunks" & pos(0) then { } else
#line 140 "totex.nw"
#line 156 "totex.nw"
warn_unknown("xref " || tab(upto(' \t') | 0))
#line 140 "totex.nw"
} else
#line 160 "totex.nw"
if ="@index " then {
#line 168 "totex.nw"
if ="nl" & pos(0) then { write(if \code then "\\eatline" else "%")}else
if =("defn "|"localdefn ") then
#line 172 "totex.nw"
/noindex &
#line 169 "totex.nw"
{
#line 181 "totex.nw"
writes("\\nosublabel{", \lastxreflabel, "}")
writes("\\nwindexdefn{", TeXliteral(name := tab(0)), "}{", indexlabel(name), "}{",
\lastxrefref, "}")
#line 154 "totex.nw"
every lastxreflabel | lastxrefref := &null
#line 169 "totex.nw"
} else
if ="use " then
#line 172 "totex.nw"
/noindex &
#line 170 "totex.nw"
{
#line 189 "totex.nw"
if /code then {
writes("\\protect\\nosublabel{", \lastxreflabel, "}")
writes("\\protect\\nwindexuse{", TeXliteral(name := tab(0)), "}{",
indexlabel(name), "}{", \lastxrefref, "}")
}
#line 154 "totex.nw"
every lastxreflabel | lastxrefref := &null
#line 170 "totex.nw"
} else
#line 199 "totex.nw"
if ="begindefs" & pos(0) then
#line 172 "totex.nw"
/noindex &
#line 199 "totex.nw"
{ writes("\\nwidentdefs{") } else
if ="isused " then
#line 172 "totex.nw"
/noindex &
#line 200 "totex.nw"
{ "handled by latex" } else
if ="defitem " then
#line 172 "totex.nw"
/noindex &
#line 201 "totex.nw"
{ i := tab(0);
#line 209 "totex.nw"
writes("\\\\{{", TeXliteral(i), "}{", indexlabel(i), "}}")
#line 201 "totex.nw"
} else
if ="enddefs" & pos(0) then
#line 172 "totex.nw"
/noindex &
#line 202 "totex.nw"
{ writes("}") } else
if ="beginuses" & pos(0) then
#line 172 "totex.nw"
/noindex &
#line 203 "totex.nw"
{ writes("\\nwidentuses{"); ulist := [] } else
if ="isdefined " then
#line 172 "totex.nw"
/noindex &
#line 204 "totex.nw"
{ "latex finds the definitions" } else
if ="useitem " then
#line 172 "totex.nw"
/noindex &
#line 205 "totex.nw"
{ i := tab(0);
#line 209 "totex.nw"
writes("\\\\{{", TeXliteral(i), "}{", indexlabel(i), "}}")
#line 205 "totex.nw"
put(ulist, i); } else
if ="enduses" & pos(0) then
#line 172 "totex.nw"
/noindex &
#line 207 "totex.nw"
{ writes("}");
#line 211 "totex.nw"
every i := !ulist do
writes("\\nwindexuse{", TeXliteral(i), "}{", indexlabel(i), "}{", \lastdefnlabel, "}")
#line 207 "totex.nw"
} else
#line 228 "totex.nw"
if ="beginindex" & pos(0) then
#line 172 "totex.nw"
/noindex &
#line 228 "totex.nw"
{ } else
if ="entrybegin " then
#line 172 "totex.nw"
/noindex &
#line 229 "totex.nw"
{ label := tab(upto(' ')); =" "; name := tab(0)
write("\\nwixlogsorted{i}{{", TeXliteral(name),
"}{", indexlabel(name), "}}%") } else
if ="entryuse " then
#line 172 "totex.nw"
/noindex &
#line 232 "totex.nw"
{ "handled by latex" } else
if ="entrydefn " then
#line 172 "totex.nw"
/noindex &
#line 233 "totex.nw"
{ "handled by latex" } else
if ="entryend" & pos(0) then
#line 172 "totex.nw"
/noindex &
#line 234 "totex.nw"
{ } else
if ="endindex" & pos(0) then
#line 172 "totex.nw"
/noindex &
#line 235 "totex.nw"
{ } else
#line 160 "totex.nw"
#line 162 "totex.nw"
warn_unknown("index " || tab(upto(' \t') | 0))
#line 160 "totex.nw"
} else
#line 120 "totex.nw"
if ="@quote" & pos(0) then { quoting := 1 ; writes("{\\tt{}") } else
if ="@endquote" & pos(0) then { quoting := &null ; writes("}") } else
if ="@file " then { filename := tab(0);
#line 154 "totex.nw"
every lastxreflabel | lastxrefref := &null
#line 123 "totex.nw"
\delay | writes("\\nwfilename{", filename, "}") } else
if ="@literal " then { writes(tab(0)) } else
if ="@header latex " then {
#line 130 "totex.nw"
writes("\\documentstyle[noweb]{article}\\pagestyle{noweb}\\noweboptions{", tab(0),
"}\\begin{document}")
#line 125 "totex.nw"
} else
if ="@header tex " then { writes("\\input nwmac ") } else
if ="@trailer latex" & pos(0) then { write("\\end{document}") } else
if ="@trailer tex" & pos(0) then { write("\\bye") } else
#line 53 "totex.nw"
if ="@" then # follows last else
warn_unknown(1(tab(upto(' ')|0), pos(0) | move(1)))
else
write(&errout, "Botched line in noweb pipeline: ", tab(0))
#line 17 "totex.nw"
}
write()
end
#line 109 "totex.nw"
procedure label2tag(label)
return "{\\nwtagstyle{}\\subpageref{" || label || "}}"
end
#line 239 "totex.nw"
procedure escape(line, chars, prefix)
/prefix := "\\"
line ? {
s := ""
while s ||:= tab(upto(chars)) do s ||:= prefix || move(1)
return s || tab(0)
}
end
#line 248 "totex.nw"
global TeXspecials
#line 257 "totex.nw"
procedure TeXliteral(arg)
static nospace, code
initial { codes := ["\\", 92, "{", 123, "}", 125, "$", 36, "&", 38, "#", 35, "^", 94,
"_", 95, "%", 37, "~", 126]
code := table()
while (c := get(codes), n := get(codes)) do code[c] := string(n)
if c := !TeXspecials & c ~== " " & not member(code, c) then
stop("internal error, character-code mismatch, report a bug!")
}
s := ""
arg ? {
while s ||:= tab(upto(TeXspecials)) do {
c := move(1)
if member(code, c) then
s ||:= "{\\char" || code[c] || "}"
else
s ||:= "\\" || c
}
return s || tab(0)
}
end
#line 282 "totex.nw"
procedure convquotes(s)
r := ""
s ? {
while r ||:= tab(find("[[")) do {
="[[" | stop("impossible missing [[")
r ||:= "\\code{}" || TeXliteral(tab(find("]]")))
r ||:= tab(many(']')-2)
="]]" | stop("impossible missing ]]")
r ||:= "\\edoc{}"
}
return r || tab(0)
}
end
#line 296 "totex.nw"
procedure warn_unknown(tag)
static warned
initial warned := set()
if not member(warned, tag) then {
write(&errout, "Warning: unrecognized escape @", tag, tab(0))
insert(warned, tag)
}
return
end
#line 308 "totex.nw"
procedure indexlabel(ident)
static badset, trans
initial {
#line 322 "totex.nw"
trans := table()
trans[" "] := "sp" # space
trans["#"] := "has" # hash
trans["$"] := "do" # dollar
trans["%"] := "pe" # percent
trans["&"] := "am" # ampersand
trans[","] := "com" # commad
trans[":"] := "col" # colon
trans["\\"] := "bs" # backslash
trans["^"] := "hat" # hat
trans["_"] := "un" # underscore
trans["{"] := "lb" # left brace
trans["}"] := "rb" # right brace
trans["~"] := "ti" # tilde
#line 312 "totex.nw"
badset := ''
every badset ++:= key(trans)
}
ident ? {
s := ""
while s ||:= tab(upto(badset)) do s ||:= ":" || trans[move(1)]
return s || tab(0)
}
end